import 'package:flutter/material.dart';
import 'package:flutter_saixiaoli/pages/activity/activeDetail/shareSheet.dart';
import 'package:flutter_saixiaoli/pages/activity/activeDetail/swiperIndicator.dart';
import 'package:flutter_saixiaoli/pages/activity/activeDetail/tabs.dart';
import 'package:flutter_saixiaoli/pages/activity/match/bmNumber.dart';
import 'package:flutter_saixiaoli/pages/activity/match/bmPlace.dart';
import 'package:flutter_saixiaoli/pages/activity/match/bmWidget.dart';
import 'package:flutter_saixiaoli/pages/activity/match/bottomSheet.dart';
import 'package:flutter_saixiaoli/pages/activity/match/bottomWidget.dart';
import 'package:flutter_saixiaoli/pages/activity/match/titleWidget.dart';
import 'package:flutter_saixiaoli/routes.dart';

import 'package:flutter_swiper/flutter_swiper.dart';

class MatchDetail extends StatefulWidget {
  @override
  State<MatchDetail> createState() => _MatchDetailState();
}

class _MatchDetailState extends State<MatchDetail>
    with SingleTickerProviderStateMixin {
  bool textShow = false;
  int state = 0; //0是报名开始，1是报名截止 2是比赛开始
  TabController tabc;
  List tabs = [
    {'name': '活动介绍'},
    {'name': '报名须知'},
    {'name': '优选商品'}
  ];

  void initState() {
    super.initState();
    tabc = new TabController(length: tabs.length, vsync: this);
    // tabc.addListener(() {
    //   setState(() {
    //     tabIndex = tabc.index;
    //   });
    // });
  }

  //分享弹窗
  shareSheetWidget(double height) {
    return Container(
        //margin: EdgeInsets.only(bottom: 55),
        padding: EdgeInsets.symmetric(vertical: 12),
        height: height,
        color: Colors.white,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Container(
              child: Column(
                children: [
                  Container(
                    child: Image.asset(
                      'images/active/wx.png',
                      width: 45,
                      height: 45,
                    ),
                  ),
                  Container(
                      child: Text(
                        '微信',
                        style: TextStyle(fontSize: 12),
                      ),
                      margin: EdgeInsets.only(top: 10))
                ],
              ),
            ),
            Container(
              child: Column(
                children: [
                  Container(
                    child: Image.asset(
                      'images/active/pyq.png',
                      width: 45,
                      height: 45,
                    ),
                  ),
                  Container(
                      child: Text(
                        '分享朋友圈',
                        style: TextStyle(fontSize: 12),
                      ),
                      margin: EdgeInsets.only(top: 10))
                ],
              ),
            ),
            Container(
              child: Column(
                children: [
                  Container(
                    child: Image.asset(
                      'images/active/hb.png',
                      width: 45,
                      height: 45,
                    ),
                  ),
                  Container(
                      child: Text(
                        '生成海报',
                        style: TextStyle(fontSize: 12),
                      ),
                      margin: EdgeInsets.only(top: 10))
                ],
              ),
            ),
          ],
        ));
  }

  @override
  Widget build(BuildContext context) {
    List swiperList = [
      Container(
        width: MediaQuery.of(context).size.width,
        color: Colors.red,
      ),
      Container(
        width: MediaQuery.of(context).size.width,
        color: Colors.yellow,
      ),
      Container(
        width: MediaQuery.of(context).size.width,
        color: Colors.green,
      ),
    ];
    return Scaffold(
      appBar: AppBar(
        title: Text('赛事详情'),
        centerTitle: true,
        elevation: 0,
      ),
      body: Flex(
        direction: Axis.vertical,
        children: [
          Expanded(
              child: SingleChildScrollView(
            child: Column(
              children: [
                //轮播图
                Container(
                  height: 180,
                  child: Swiper(
                    itemCount: swiperList.length,
                    itemBuilder: (context, index) {
                      return Container(
                        child: swiperList[index],
                      );
                    },
                    pagination: SwiperPagination(
                      alignment: Alignment.bottomRight,
                      builder:
                          SwiperCustomPagination(builder: (context, config) {
                        return SwiperIndicator.indicator(
                            current: config.activeIndex + 1,
                            length: swiperList.length,
                            textShow: this.textShow);
                      }),
                    ),
                  ),
                ),
                //标题模块
                TitleWidget(),
                //报名图标模块
                BmWidget(
                  state: this.state,
                ),
                //报名数量模块
                BmNumber(),
                //报名地址
                BmPlace(),
                Tabs(tabc: tabc, tabs: tabs),

              ],
            ),
          )),
          Container(
            decoration: BoxDecoration(boxShadow: [
              BoxShadow(
                  color: Color.fromRGBO(187, 187, 187, 0.4),
                  offset: Offset(0.0, 5.0), //阴影xy轴偏移量
                  blurRadius: 15.0, //阴影模糊程度
                  spreadRadius: 1.0)
            ], color: Colors.white),
            height: 55,
            child: Row(
              children: [
                Container(
                  width: MediaQuery.of(context).size.width * 0.5,
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Material(
                        child: InkWell(
                          onTap: () {
                            ShareSheet.show(context,
                                options: shareSheetWidget(100));
                          },
                          child: Row(
                            children: [
                              Container(
                                child: Icon(
                                  Icons.share,
                                  color: Color.fromRGBO(136, 136, 136, 1),
                                  size: 15,
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(left: 5),
                                child: Text(
                                  '分享',
                                  style: TextStyle(
                                      color: Color.fromRGBO(136, 136, 136, 1),
                                      fontSize: 12),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.symmetric(horizontal: 12),
                        width: 1,
                        height: 16,
                        color: Color.fromRGBO(221, 221, 221, 1),
                      ),
                      Container(
                        child: Icon(
                          Icons.new_releases,
                          color: Color.fromRGBO(136, 136, 136, 1),
                          size: 15,
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 5),
                        child: Text(
                          '咨询',
                          style: TextStyle(fontSize: 12),
                        ),
                      )
                    ],
                  ),
                ),
                Material(
                  color: Color.fromRGBO(191, 55, 54, 1),
                  child: InkWell(
                    onTap: () {
                      bottomSheet().showCustomModalBottomSheet(context,
                          title: bottomWidget().title(),
                          options: bottomWidget().options(),bottomBtn:bottomWidget().bottomBtn());
                    },
                    child: Container(
                      width: MediaQuery.of(context).size.width * 0.5,
                      alignment: Alignment.center,
                      child: Text(
                        '立即报名',
                        style: TextStyle(fontSize: 15, color: Colors.white),
                      ),
                    ),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
